home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: uu4news.netcom.com!zodiac!szh
- From: szh@zcon.com (Syed Zaeem Hosain)
- Subject: Re: Bit Masking
- Message-ID: <1996Jan11.133059.7153@zcon.com>
- Sender: szh@zcon.com (Syed Zaeem Hosain)
- Nntp-Posting-Host: zodiac
- Reply-To: szh@zcon.com
- Organization: Z Consulting Group
- References: <DKz5y4.8En@twisto.eng.hou.compaq.com>
- Date: Thu, 11 Jan 1996 13:30:59 GMT
-
- In article <DKz5y4.8En@twisto.eng.hou.compaq.com>, garyc%cs%contractors@bangate.compaq.com (Gary Clarke) writes:
- >Can someone tell me the elegent way to clear specific bits from a
- >byte, e.g.
- >
- ># define BIT_1 1
- ># define BIT_2 2
- ># define BIT_3 4
- ># define BIT_4 8
- >
- >Set the bit: x |= BIT_x
- >
- >Clear the bit using BIT_x: ????
-
- The following:
-
- x &= ~BIT_x;
-
- will clear the bit. But be careful to use unsigned variables to avoid
- surprises with sign bits! :-)
-
- Z
-
-
- --
- -------------------------------------------------------------------------
- | Syed Zaeem Hosain P. O. Box 610097 (408) 441-7021 |
- | Z Consulting Group San Jose, CA 95161 szh@zcon.com |
- -------------------------------------------------------------------------
-